#include "node.h"
#include "search.h"

void st_init()
{ 
  head = (z = new(nullItem, 0, 0, 0)); 
}

int st_count() 
{ 
  return head->N; 
}

info searchR(link h, char v)
{ 
  char t = key(h->item);
  if (h == z) 
    return nullItem;
  if eq(v, t) 
	 return h->item;
  if less(v, t) 
	   return searchR(h->l, v);
  else 
    return searchR(h->r, v);
}

info st_search(char v) 
{ 
  return searchR(head, v); 
} 

link insertR(link h, info item)
{ 
  char v = key(item), t = key(h->item);
  if (h == z) 
    return new(item, z, z, 1);
  if less(v, t) 
	   h->l = insertR(h->l, item);
  else 
    h->r = insertR(h->r, item);
  (h->N)++; 
  return h;
}

void st_insert(info item)
{ 
  head = insertR(head, item); 
}

info bstsearch(char v)
{
    return searchR(head, v);
}
